<!--
 * @Author: your name
 * @Date: 2021-09-11 15:28:48
 * @LastEditTime: 2021-12-27 10:35:19
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jinfeng_up\src\components\bugRowsDialog\bugRowsDialog.vue
-->
<template>
  <div>
    <!-- 关闭弹出框 -->
    <CommonDialog
      title="绑定BUG"
      width="75%"
      v-bind:dialogVisible="bugsDialogVisible"
      @on-change-dialogVisible="closeChange"
      class="bugs"
      top="10vh"
    >
      <template #body>
        <el-form class="closeForm" :rules="closeFormRules" :model="bugsForm" ref="bugsForm" label-width="100px" label-position="top">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="ID" prop="id" >
                <el-input v-model.number="bugsForm.id" @input="changeIDs" ><el-button style="background: #409EFF;color:#fff;" slot="append" type="primary"  @click="searchIDforBug" icon="el-icon-search">查询</el-button> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="BUG状态">
                <el-input v-model="bugsForm.statusCn" disabled> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="计划解决版本/日期">
                <el-input v-model="bugsForm.keywords" disabled> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="解决版本">
                <el-input v-model="bugsForm.resolvedBuildName" disabled> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="标题" class="solutionVersion">
                <el-input v-model="bugsForm.title" disabled> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="解决方案" class="solutionVersion">
                <el-input v-model="bugsForm.resolutionCn" disabled > </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <template #dialog_footer>
        <el-button class="submitCancel" @click="closeCancel">取 消</el-button>
        <el-button type="primary" @click="confirmClose('closeForm')" class="submitReme" :disabled="isClick">确认</el-button>
      </template>
    </CommonDialog>
  </div>
</template>

<script>
import CommonDialog from '@/components/commonDialog/commonDialog.vue'
import { FeedBack } from '@/api/feedBack/server'
export default {
    name: '',
    components: {
        CommonDialog
    },
    props: {},
    data() {
        return {
            isClick: true,
            bugsDialogVisible: false,
            feedBackNumber: '',
            pageId: '',
            closeFormRules: {
                id: [
                    { required: true, message: 'ID不能为空', trigger: 'blur' },
                    { type: 'number', message: 'ID必须为数字值', trigger: 'change' }
                ]
            },
            bugsForm: {
                id: null,
                statusCn: '',
                keywords: '',
                resolvedBuildName: '',
                resolutionCn: ''
            }
        }
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
    // this.getCloseFeedBackReasonList()
    },
    methods: {
        changeIDs() {
            this.isClick = true
        },
        show(number, pageId) {
            console.log(number, pageId)
            this.feedBackNumber = number
            this.pageId = pageId
            this.bugsDialogVisible = true
            this.isClick = true
            this.bugsForm.id = null
        },
        searchIDforBug() {
            this.toBugs()
        },
        async toBugs() {
            console.log(this.bugsForm.id, this.pageId)
            try {
                const result = await FeedBack.getBugDetail({ zenTaoBugId: this.bugsForm.id, feedbackId: this.pageId })
                if (result.success) {
                    const array = result.data.checkBugList[0]
                    this.$message.success('Id存在，请绑定')
                    this.isClick = false
                    this.bugsForm.statusCn = array.statusCn
                    this.bugsForm.keywords = array.keywords
                    this.bugsForm.resolvedBuildName = array.resolvedBuildName
                    this.bugsForm.resolutionCn = array.resolutionCn
                    this.bugsForm.title = array.title
                } else {
                    this.bugsForm = {
                        id: null,
                        statusCn: '',
                        keywords: '',
                        resolvedBuildName: '',
                        resolutionCn: ''
                    }
                    this.$message.error(result.message || 'Id不存在')
                }
            } catch (err) {
                console.log(err)
            }
        },
        closeChange(val) {
            this.bugsDialogVisible = val
            this.bugsForm = {
                id: null,
                statusCn: '',
                keywords: '',
                resolvedBuildName: '',
                resolutionCn: ''
            }
            this.$refs['bugsForm'].resetFields()
        },
        closeCancel() {
            this.bugsDialogVisible = false
            this.bugsForm = {
                id: '',
                statusCn: '',
                keywords: '',
                resolvedBuildName: '',
                resolutionCn: ''
            }
        },
        async confirmClose() {
            try {
                const result = await FeedBack.associateBugOrStory({ bugOrStoryId: this.bugsForm.id, feedBackNumber: this.feedBackNumber, type: 'bug' })
                if (result.success) {
                    this.$message.success('绑定成功')
                    this.bugsForm = {
                        id: null,
                        statusCn: '',
                        keywords: '',
                        resolvedBuildName: '',
                        resolutionCn: ''
                    }
                    this.$emit('refreshPage')
                    this.bugsDialogVisible = false
                } else {
                    this.bugsForm = {
                        id: null,
                        statusCn: '',
                        keywords: '',
                        resolvedBuildName: '',
                        resolutionCn: ''
                    }
                    this.$message.error(result.message)
                    this.bugsDialogVisible = false
                }
            } catch (err) {
                console.log(err)
            }
        }
    }
}
</script>
